
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:nft_shop/market/conteroller/market_conteroller.dart';
import 'package:nft_shop/my/model/models.dart';
import 'package:nft_shop/net/service_repository.dart';
import 'package:nft_shop/res/global.dart';
import 'package:nft_shop/widgets/my_app_bar.dart';

class DrawerScreenPage extends StatefulWidget {
  const DrawerScreenPage({Key? key}) : super(key: key);

  @override
  _DrawerScreenPageState createState() => _DrawerScreenPageState();
}

class _DrawerScreenPageState extends State<DrawerScreenPage> {

  List<String> categoryList = ["全部","藏品","盲盒"];
  List<SpecialTypeModel> typeList = [];
  List<String> specialList = [];

  late MarketConteroller _conteroller;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _conteroller = MarketConteroller.to;
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.only(left: 92),
      child: Scaffold(
        appBar: PreferredSize(
          preferredSize: Size.fromHeight(20),
          child: AppBar(

          ),
        ),
        body: GetBuilder<MarketConteroller>(
          id:MarketConteroller.MarketScreeningID,
          builder: (logic) {
            return Container(
              padding: EdgeInsets.symmetric(horizontal: 15),
              child: Column(
                children: [
                  _buildCategoryWidget(),
                  logic.typeList.length == 0?Container():SizedBox(height: 20,),
                  // logic.typeList.length == 0?Container():_buildTypeWidget(),
                  // specialList.length == 0?Container():SizedBox(height: 20,),
                  // specialList.length == 0?Container():_buildSpecialWidget()
                ],
              ),
            );
          }
        )
      ),
    );
  }

  //品类
  _buildCategoryWidget(){
    int current;
    if(_conteroller.currentIndex == 0){
      current = _conteroller.selectCategoryNum;
    }else{
      current = _conteroller.selectSellCategoryNum;
    }

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text("品类",style: TextStyle(fontSize: 14,color: Global.kTheme.textPrimary4,fontFamily: Global.mySemiboldFont),),
        GridView.builder(
          shrinkWrap: true,
          padding:EdgeInsets.only(top: 10,),
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 3,
            mainAxisSpacing: 8,
            crossAxisSpacing: 8,
            childAspectRatio: 80/28,
          ),
          itemBuilder: (context, index) {
            return InkWell(
              onTap: (){
                if(_conteroller.currentIndex == 0){
                  _conteroller.selectCategoryNum = index;
                }else{
                  _conteroller.selectSellCategoryNum = index;
                }
                Get.back();
              },
              child: Container(
                decoration: BoxDecoration(
                  color: current == index?Global.kTheme.colorBackground3:Global.kTheme.colorLine,
                  borderRadius: BorderRadius.circular(4),
                ),
                child: Center(child: Text(categoryList[index],style: TextStyle(fontSize: 12,color: current == index?Global.kTheme.textPrimary5:Global.kTheme.textPrimary1,fontFamily: Global.mySemiboldFont),)),
              ),
            );
          },
          itemCount: categoryList.length,
        ),
      ],
    );
  }

  //类型
  _buildTypeWidget(){
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text("类型",style: TextStyle(fontSize: 14,color: Global.kTheme.textPrimary4,fontFamily: Global.mySemiboldFont),),
        GridView.builder(
          shrinkWrap: true,
          padding:EdgeInsets.only(top: 10,),
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 3,
            mainAxisSpacing: 8,
            crossAxisSpacing: 8,
            childAspectRatio: 80/28,
          ),
          itemBuilder: (context, index) {
            SpecialTypeModel model = _conteroller.typeList[index];

            return InkWell(
              onTap: (){
                _conteroller.selectTypeNum = index;
              },
              child: Container(
                decoration: BoxDecoration(
                  color: _conteroller.selectTypeNum == index?Global.kTheme.colorBackground3:Global.kTheme.colorLine,
                  borderRadius: BorderRadius.circular(4),
                ),
                child: Center(child: Text(model.title??"",style: TextStyle(fontSize: 12,color: _conteroller.selectTypeNum == index?Global.kTheme.textPrimary5:Global.kTheme.textPrimary1,fontFamily: Global.mySemiboldFont),)),
              ),
            );
          },
          itemCount: _conteroller.typeList.length,
        ),
      ],
    );
  }

  //专题
  _buildSpecialWidget(){
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text("专题",style: TextStyle(fontSize: 14,color: Global.kTheme.textPrimary4,fontFamily: Global.mySemiboldFont),),
        GridView.builder(
          shrinkWrap: true,
          padding:EdgeInsets.only(top: 10,),
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 3,
            mainAxisSpacing: 8,
            crossAxisSpacing: 8,
            childAspectRatio: 80/28,
          ),
          itemBuilder: (context, index) {
            return InkWell(
              onTap: (){
                _conteroller.selectSpecialNum = index;
              },
              child: Container(
                decoration: BoxDecoration(
                  color: _conteroller.selectSpecialNum == index?Global.kTheme.colorBackground3:Global.kTheme.colorLine,
                  borderRadius: BorderRadius.circular(4),
                ),
                child: Center(child: Text(categoryList[index],style: TextStyle(fontSize: 12,color: _conteroller.selectSpecialNum == index?Global.kTheme.textPrimary5:Global.kTheme.textPrimary1,fontFamily: Global.mySemiboldFont),)),
              ),
            );
          },
          itemCount: specialList.length,
        ),
      ],
    );
  }
}
